#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2021/7/7 16:21
# @Author    :cjw
from typing import Optional

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


# 启动命令 uvicorn hello_world:app --reload

class CityInfo(BaseModel):
	province: str  # 省
	country: str  # 市
	is_affected: Optional[bool] = None  # 是否有感染


# @app.get('/')
# def hello_world():
# 	return {'hello': 'world!'}
#
#
# @app.get('/city/{city}')
# def result(city: str, query_string: Optional[str] = None):
# 	return {'city': city, 'query_string': query_string}
#
#
# @app.put('/city/{city}')
# def result_put(city: str, city_info: CityInfo):
# 	return {'city': city, 'country': city_info.country, 'is_affected': city_info.is_affected}

@app.get('/')
async def hello_world():
	return {'hello': 'world!'}


@app.get('/city/{city}')
async def result(city: str, query_string: Optional[str] = None):
	return {'city': city, 'query_string': query_string}


@app.put('/city/{city}')
async def result_put(city: str, city_info: CityInfo):
	return {'city': city, 'country': city_info.country, 'is_affected': city_info.is_affected}
